package cn.johnyu.controller;

import cn.johnyu.domain.Book;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Slf4j
@RestController
public class BookController {

    @GetMapping("/books")
    public List<Book> findAll(){

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        log.info("当前用户："+authentication.getName());

        log.info("当前用户的权限：");
        authentication.getAuthorities().forEach(a->log.info(a.getAuthority()));

        return List.of(new Book(1,"Java"),new Book(2,"Python"));
    }
}
